#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include <sstream>
#include <limits>

using namespace std;

const int NINF = numeric_limits<int>::min();

vector<int> cost;  // vector de costos
vector<int> parent; // vector de padres

int recursive_top_down(const vector<int>& input, int i) {
   if(cost[i] > NINF) {
      return cost[i];
   }

   cost[i] = 1;

   for(int j = i-1; j >= 0; j--){   
      int cj = recursive_top_down(input, j);

      if(input[j] < input[i]) {
         cost[i] = max(cost[i], cj + 1);

         if (cost[i] == cj + 1) {
            cost[i] = 1 + cj;
            parent[i] = j;               
         }
      }
   }
   return cost[i];
}

int top_down(const vector<int>& input) {
   cost  .assign(input.size(), NINF);
   parent.assign(input.size(), -1);
   
   cost[0] = 1;

   recursive_top_down(input, input.size() - 1);

   int index = 0;
      
   for(unsigned i = 1; i < cost.size(); i++){
      if(cost[i] > cost[index]){
         index = i;
      }
   }
   
   return index;
}


int bottom_up(const vector<int>& input){
   cost  .assign(input.size(),  1);
   parent.assign(input.size(), -1);
   
   for(unsigned i = 0; i < input.size(); i++){
      for(unsigned j = i+1; j < input.size(); j++){
         if(input[j] > input[i]) {
            cost[j] = max(cost[j], cost[i] + 1);

            if (cost[j] == cost[i] + 1) {
               cost[j] = 1 + cost[i];
               parent[j] = i;               
            }
         }
      }
   }
   
   int index = 0;
   
   for(unsigned i = 1; i < cost.size(); i++){
      if(cost[i] > cost[index]){
         index = i;
      }
   }
   
   return index;
}

void print(int index, const vector<int>& input){
   cout << "Max hits: " << cost[index] << endl;
   
   stack<int> s;
   s.push(input[index]);

   while(parent[index] != -1){
      s.push(input[parent[index]]);
      index = parent[index];
   }

   while(!s.empty()){
      cout << s.top() << endl;
      s.pop();
   }
}

int main(){
   int ncases, value;
   string line;
  
   cin >> ncases;
   cin.ignore();
   
   getline(cin, line);
   
   for(int k=0; k<ncases; k++){
      getline(cin, line);
      vector<int> input;

      while("" != line) {
         stringstream sin(line);         
         sin >> value;
         input.push_back(value);
         getline(cin, line);
      }

      #ifdef TOPDOWN
         print(top_down(input), input);
      #else
         print(bottom_up(input), input);
      #endif
      
      if((k+1) < ncases){
         cout << endl;
      }
   }
      
   return 0;
}

